package com.y.multition;

import java.util.ArrayList;

/**
 * 线程安全单例
 * @author Administrator
 *
 */
public class Emperor {

	private static ArrayList<Emperor> emList = new ArrayList();
	private final static Integer NUM = 2;
	
	private String numStr;
	
	private Emperor(String numStr) {
		this.numStr = numStr;
	}
	
	public static Emperor getInstance(Integer emNum) {
		if(emList.size() >= emNum) {
			return emList.get(emNum);
		}
		return emList.get(emList.size() - 1);
	}
	
	public static Emperor getInstance() {
//		System.out.println(emList.size());
		if(emList.size() < NUM) {
			emList.add(new Emperor(String.valueOf(emList.size() + 1)));
		}
		return emList.get(emList.size() - 1);
	}
	
	public void sayName() {
		System.out.println(numStr);
	}
	
}
